

package com.hazelcast.map.impl.operation;

import com.hazelcast.internal.serialization.Data;
import com.hazelcast.map.impl.MapDataSerializerHook;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;

import java.io.IOException;

public class PutIfAbsentWithExpiryOperation extends PutIfAbsentOperation {

    private long ttl;
    private long maxIdle;

    public PutIfAbsentWithExpiryOperation(String name, Data dataKey, Data value, long ttl, long maxIdle) {
        super(name, dataKey, value);
        this.ttl = ttl;
        this.maxIdle = maxIdle;
    }

    public PutIfAbsentWithExpiryOperation() {
    }

    @Override
    protected long getTtl() {
        return ttl;
    }

    @Override
    protected long getMaxIdle() {
        return maxIdle;
    }

    @Override
    public int getClassId() {
        return MapDataSerializerHook.PUT_IF_ABSENT_WITH_EXPIRY;
    }

    @Override
    protected void writeInternal(ObjectDataOutput out) throws IOException {
        super.writeInternal(out);
        out.writeLong(ttl);
        out.writeLong(maxIdle);
    }

    @Override
    protected void readInternal(ObjectDataInput in) throws IOException {
        super.readInternal(in);
        ttl = in.readLong();
        maxIdle = in.readLong();
    }
}
